/**
 * 
 */
package edu.umd.clip.smoothing;

/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 * One-count smoothing as described in Chen's thesis
 */
public class OneCountSmoother extends Smoother {
	private final double alpha;
	private final double backoffProb;
	private final double totalCountPlusAlpha;
	
	public OneCountSmoother(SmootherProducer producer, double beta, double gamma) {
		super(producer);
		int counts[] = producer.getCounts();
		
		alpha = gamma * (counts[1] + beta);
		totalCountPlusAlpha = alpha + totalCount;
		backoffProb = alpha / totalCountPlusAlpha;
		//System.out.printf("OneCount: alpha=%g, backoff=%g, count=%d\n", alpha, backoffProb, totalCount);
	}

	/* (non-Javadoc)
	 * @see edu.umd.clip.smoothing.Smoother#getBackoffProb()
	 */
	@Override
	public double getBackoffProb() {
		return backoffProb;
	}

	/* (non-Javadoc)
	 * @see edu.umd.clip.smoothing.Smoother#getProb(long)
	 */
	@Override
	public double getProb(long count) {
		if (count < minCount) return 0.0; 
		return count / totalCountPlusAlpha;
	}

}
